package com.adroiti.texasholdem.engine;

import com.adroiti.texasholdem.Card;
import com.adroiti.texasholdem.Color;

public class SimpleCard implements Card {

	private Color color;
	private int rank;

	public SimpleCard(Color color, int rank) {
		this.color = color;
		this.rank = rank;
	}

	public int getRank() {
		return rank;
	}

	public Color getColor() {
		return color;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((color == null) ? 0 : color.hashCode());
		result = prime * result + rank;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SimpleCard other = (SimpleCard) obj;
		if (color != other.color)
			return false;
		if (rank != other.rank)
			return false;
		return true;
	}

	@Override
	public String getTitleLetter() {
		String abc = "JQKA";
		if (rank >= 11) {
			int i = rank - 11;
			return abc.substring(i, i + 1);
		}
		return new Integer(rank).toString();
	}

	@Override
	public int compareTo(Card o) {
		if(getRank() == o.getRank()){
			return 0;
		}
		else if(getRank() > o.getRank()){
			return 1;
		}
		else return -1;
	}
	
	@Override
	public String toString(){
		return this.getColor().getTitleLetter()+getTitleLetter();
	}

}
